<table class="calendar-news" cellpadding="0" cellspacing="0" >
<tr>
<?php
	// liczba rekordow
	$catsCnt = count($items);
	$columns = $columns;
?>
    	
    	
<?php
	$i = 0; 
	foreach ($items as $k => $item) {
	$i++;
?>		
		
<?php     	
        if(($k+1) % $columns == 0) { 
            echo "<td style=\"width:".(100/$columns)."%;text-align: left; \" align=\"left\" valign=\"top\">";
?>
		<table class="hompage-one-news" width="100%" cellpadding="0" cellspacing="0">
			<tr>
				<td colspan="2" class="news-homepage-header">
					<h2 class="homepage-news-title corners-left-top corners-right-top"><?php echo nl2br($item['News']['name'])?></h2>
				</td>
			</tr>
			<?php if($i == 1){?>
			<tr>
				<td valign="top"  class="text" colspan="2">
				
					<?php $thumb = $fileUpload->image($item['NewUpload']['name'],array('autoResize'=>true,'width'=>180,'imagePathOnly'=>true));?>
					<p style="float: left; padding: 10px; ">
					<?php echo $this->Html->link("&nbsp;", array('plugin'=>'calendar','controller'=>'news','action' => 'view', $item['News']['id'],Inflector::slug($item['News']['name'],'-')),array('escape'=>false,'class'=>"highslide news-image-first", 'title'=>$item['News']['name'], 'style'=>"background: url(".$thumb.") center no-repeat;")); ?>
					</p>
					<p>
						<?php $content = $this->Text->truncate(
							    $item['News']['content'],
							    700,
							    array(
							        'ending' => '...',
							        'exact' => false
							    ));?>
				    	<?php echo nl2br($content)?>	
					</p>	
        		</td>
        	</tr>			
			<?php }else{?>
			<tr>

				<?php $thumb = $fileUpload->image($item['NewUpload']['name'],array('autoResize'=>true,'width'=>90,'imagePathOnly'=>true));?>
			 	<?php if(!empty($thumb)){?>
				<td width="60" class="news-image">
					
					<?php $thumb = (!empty($thumb)) ? rtrim($this->webroot,'/').$thumb : $logo;?>
					<?php echo $this->Html->link("&nbsp;", array('plugin'=>'calendar','controller'=>'news','action' => 'view', $item['News']['id'],Inflector::slug($item['News']['name'],'-')),array('escape'=>false,'class'=>"highslide", 'title'=>$item['News']['name'], 'style'=>"background: url(".$thumb.") center no-repeat;")); ?>
					    	
				</td>
				<?php }?>
				<td valign="top"  class="news-content" <?php if(empty($thumb)){?>colspan="2"<?php }?>>
					<p> 
				    	<?php $content = $this->Text->truncate(
							    $item['News']['small_content'],
							    $lenght,
							    array(
							        'ending' => '...',
							        'exact' => false
							    ));?>
				    	<?php echo nl2br($content)?>	
				    </p>				
        		</td>
        	</tr>
        	<?php }?>
        	<tr>
        		<td colspan="2" class="news-hompage-fotter">
        			<span style="float: left"><?php echo __('Liczba wyświetleń: ',true)?> <?php echo $item['News']['views']?></span>
        			<?php echo $this->Html->link($this->Html->image(HOST.'/read-more.png'),array('plugin'=>'calendar','controller'=>'news','action'=>'view',$item['News']['id'],Inflector::slug($item['News']['name'],'-')),array('class'=>'link-more','escape'=>false));?>
        		</td>
        	</tr>
        </table>	
<?php       echo "</td></tr>"; 
            if ($k!=($catsCnt-1)) echo "<tr>"; 
        } else { 
            echo "<td style=\"width:".(100/$columns)."%;text-align: left; \" align=\"left\" valign=\"top\">";
?>
		<table class="hompage-one-news" width="100%" cellpadding="0" cellspacing="0">
			<tr>
				<td colspan="2" class="news-homepage-header">
					<h2 class="homepage-news-title corners-left-top corners-right-top"><?php echo nl2br($item['News']['name'])?></h2>
				</td>
			</tr>
			<tr>

				<?php $thumb = $fileUpload->image($item['NewUpload']['name'],array('autoResize'=>true,'width'=>90,'imagePathOnly'=>true));?>
				<?php if(!empty($thumb)){?>
				<td width="60" class="news-image">
					
					<?php $thumb = (!empty($thumb)) ? rtrim($this->webroot,'/').$thumb : $logo?>
					<?php echo $this->Html->link("&nbsp;", array('plugin'=>'calendar','controller'=>'news','action' => 'view', $item['News']['id'],Inflector::slug($item['News']['name'],'-')),array('escape'=>false,'class'=>"highslide", 'title'=>$item['News']['name'], 'style'=>"background: url(".$thumb.") center no-repeat;")); ?>
				</td>
				<?php }?>
				<td valign="top"  class="news-content" <?php if(empty($thumb)){?>colspan="2"<?php }?>>
					<p>		    	
			    	<?php $content = $this->Text->truncate(
						    $item['News']['small_content'],
						    $lenght,
						    array(
						        'ending' => '...',
						        'exact' => false
						    ));?>
			    	<?php echo nl2br($content)?>
			    	</p>
				</td>
			</tr>
        	<tr>
        		<td colspan="2" class="news-hompage-fotter">
        			<span style="float: left"><?php echo __('Liczba wyświetleń: ',true)?> <?php echo $item['News']['views']?></span>
        			<?php echo $this->Html->link($this->Html->image(HOST.'/read-more.png'),array('plugin'=>'calendar','controller'=>'news','action'=>'view',$item['News']['id'],Inflector::slug($item['News']['name'],'-')),array('class'=>'link-more','escape'=>false));?>
        		</td>
        	</tr>
		</table>	
 
<?php             echo "</td>"; 
        } 
	}
    // uzupełnienie ostatniego rekordu
	$numSpaces = $columns - ($catsCnt % $columns); 
    if ($numSpaces!=0 && $numSpaces != $columns ) { 
        for ($j=0;$j<$numSpaces;$j++) { 
            echo "<td style=\"width:".(100/$columns)."%;\">&nbsp;</td>"; 
        } 
        echo "</tr>"; 
    }
?>
</table>